package com.ruoyi.gams.controller;

import com.ruoyi.gams.device.led.LEDSender2010;
import com.ruoyi.gams.device.led.ScreenService;
import com.ruoyi.gams.domain.GamsWindow;
import com.ruoyi.gams.mapper.GamsWindowMapper;
import com.ruoyi.gams.mapper.GamsWindowScreenMapper;
import com.ruoyi.gams.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Api(tags = "1.设备接口")
@RestController
@RequestMapping("/device-api")
public class LEDController
{
    @Autowired
    private ScreenService screenService;

    @Autowired
    private GamsWindowMapper windowMapper;

    @Autowired
    private GamsWindowScreenMapper screenMapper;

    @ApiOperation("4.1 LED内容更新")
    @ResponseBody
    @PostMapping("/refresh")
    public Result<Object> refresh(Integer windowId)
    {
        GamsWindow window = windowMapper.selectGamsWindowById(windowId);
        screenService.refreshWindowScreen(window, LEDSender2010.ROOT_PLAY);
        return Result.success();
    }

    @ApiOperation("4.2 LED内容更新")
    @ResponseBody
    @PostMapping("/refreshWindowScreen")
    public Result<Object> refreshWindowScreen(Integer windowScreenId)
    {
        screenService.refreshWindowScreen(windowScreenId, LEDSender2010.ROOT_DOWNLOAD);
        return Result.success();
    }

    @ApiOperation("4.3 LED内容更新断电不变")
    @ResponseBody
    @GetMapping("/refreshWindowScreenDownload")
    public Result<Object> refreshWindowScreenDownload(Integer windowScreenId)
    {
        screenService.refreshWindowScreen(windowScreenId, LEDSender2010.ROOT_DOWNLOAD);
        return Result.success();
    }

}
